package com.example.translateappjava.Service.FoodDetails;

import android.app.Activity;

import com.example.translateappjava.Service.FoodCalories.FoodCaloriesHelper;

import java.io.IOException;

public class FoodDetailsHelper {
    private Activity activity;
    private FoodDetailsListener foodDetailsListener;
    public interface FoodDetailsListener{
        void getFoodDetailsResponse(String response);
    }

    public FoodDetailsHelper(Activity activity)
    {
        this.activity = activity;
    }

    public void setFoodDetailsListener(FoodDetailsListener foodDetailsListener) {
        this.foodDetailsListener = foodDetailsListener;
    }


    public void FoodDetailsRequest(String message) throws IOException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String response = null;
                try {
                    response = getFoodDetailsResponse(message);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                String finalResponse = response;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (foodDetailsListener != null) {
                            foodDetailsListener.getFoodDetailsResponse(finalResponse);
                        }
                    }
                });
            }
        }).start();

    }

    public String getFoodDetailsResponse(String message) throws IOException {
        FoodDetailsImplication foodDetailsImplication = new FoodDetailsImplication();
        return foodDetailsImplication.getFoodDetailsResult(message);
    }
}
